package com.example.as_sum.activity;

import android.os.Handler;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import com.example.as_sum.R;
import com.example.as_sum.util.OkHttpUtil;

import java.util.HashMap;
import java.util.Map;

public class HttpActivity extends BaseActivity {
private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitle("网络请求");
    }

    @Override
    public int getContentId() {
        return R.layout.activity_http;
    }

    @Override
    public void initView() {
        tv=(TextView)this.findViewById(R.id.http_tv);
    }

    @Override
    public void addListener() {

    }

    @Override
    public void loadData() {

    }
    private Handler mHandler=new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            closeDialog();
            switch (msg.what){
                case 0:
                    requestFail(msg);
                    break;
                case 1:
                    tv.setText(msg.obj.toString());
                    showShortMsg("数据返回成功");
                    break;
            }
            return false;
        }
    });
    @Override
    public Handler getHandler() {
        return mHandler;
    }
    private void loadImgData(){

    }
    public void getHtmlByCib(View view){
        showDialog("提交中。。。",false);
        String url = "http://192.168.1.117:10009/wuqinghai/Hello/login";
        Map<String,String> param= new HashMap<>();
        param.put("name","lifaran");
        OkHttpUtil.post(mHandler, url, param, 3);
    }
    public void getHtmlByBaiDu(View view){
        showDialog("提交中。。。",false);
        String url = "https://www.baidu.com/";
        OkHttpUtil.get(mHandler, url, null, 1);
    }
    public void getVersionInfo(View view){
        showDialog("提交中。。。",false);
        String url = "https://c.cib.com.cn/api/checkVersion";
        Map<String,String> param= new HashMap<>();
        OkHttpUtil.post(mHandler,url,param,2);
    }
}
